package xyz.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.net.URL;

/**
 * desc
 *
 * @author leihz
 * @date 2017/6/27 13:23
 */
public class RedisExample {



        // inject the actual template
        @Autowired
        private RedisTemplate<String, String> redisTemplate; // inject the template as ListOperations

        @Resource(name="redisTemplate")
        private ListOperations<String, String> listOps;

        public void addLink(String userId, URL url) {
            listOps.leftPush(userId, url.toExternalForm());
        }



    /*public void useCallback() {

        redisTemplate.execute(new RedisCallback<Object>() {
            @Override
            public Object doInRedis(org.springframework.data.redis.connection.RedisConnection redisConnection) throws DataAccessException {
                Long size = connection.dbSize();
                // Can cast to StringRedisConnection if using a StringRedisTemplate
                ((StringRedisConnection)connection).set("key", "value");
            }

            public Object doInRedis(RedisConnection connection) throws DataAccessException {
                Long size = connection.dbSize();
                // Can cast to StringRedisConnection if using a StringRedisTemplate
                ((StringRedisConnection)connection).set("key", "value");
            }
        });
    }*/




}
